﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class PurchasePaymentHistories :_PurchasePaymentHistories
    {
        public static PurchasePaymentHistories AddNewPayment(int purchaseOrderID, int paymentMethodID,
            Decimal paidAmt)
        {
            try
            {
                PurchasePaymentHistories histories = new PurchasePaymentHistories();
                histories.AddNew();
                histories.PurchaseOrderID = purchaseOrderID;
                histories.PaymentMethodID = paymentMethodID;
                histories.PaidAmount = paidAmt;
                histories.Deleted = false;
                histories.PaidDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
                histories.BranchID = Branches.CurrentBranchID;
                histories.Save();
                return histories;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("PurchasePaymentHistories.cs", "AddNewPayment", ex.StackTrace);
                throw ex;
            }
        }

        public void AddPayment(int poID, int paymentMethodID, Decimal paidAmt, DateTime paidDate,
            int saleUser)
        {
            AddNew();
            BranchID = Branches.CurrentBranchID;
            PurchaseOrderID = poID;
            PaymentMethodID = paymentMethodID;
            PaidAmount = paidAmt;
            PaidDate = paidDate;
            LastModifiedByUser = saleUser;
            LastModifiedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
            Deleted = false;
        }
    }
}
